package com.tisson.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.tisson.action.ActionSup;
import com.tisson.bo.DepartmentBO;
import com.tisson.bo.FilterBO;
import com.tisson.bo.PurviewBO;
import com.tisson.bo.UserBO;
import com.tisson.comment.WebConstants;
import com.tisson.pojo.Area;
import com.tisson.pojo.Page;

public class PurviewAction extends ActionSup{
	
	private String userId;
	private String callId;
	private String workerNO;
	private Date expiryDate;
	private String userDepartment;
	private String username;
	private String password;
	private String userPhone;
	private String userEmail;
	private Integer userState;
	private List result;
	private List deptList;
	private List stateList;
	private Page page;
	private String id;
	private String logicMark0;
	private String logicMark1;
	private String logicMark2;
	private String logicMark3;
	private String doorId;
	private String areaId;
	private String districtId;
	private String buildingId;
	private List areaList;
	private List districtList;
	private List buildingList;
	private List doorList; 

	public String mdsupSearch(){
		UserBO bo = new UserBO();
		page = new Page();
		List all;
		result = new ArrayList();
		try{
			all = bo.search(request,workerNO, username, callId, userDepartment, userState, logicMark0, logicMark1, logicMark2, logicMark3);
		}
		catch(Exception e){
			e.printStackTrace();
			all = new ArrayList();
		}
		request.getSession().setAttribute("list", all);
		try{
			for(int i=0;i<WebConstants.PAGESIZE;i++){
				if(all.get(i)!=null){
					result.add(all.get(i));
				}
			}
		}catch(Exception e){
		}
		page.setCurrentPage(1);
		page.setPrePage(page.getCurrentPage()-1);
		page.setNextPage(page.getCurrentPage()+1);
		page.setListSize(all.size());
		page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
		return "mdsupList";
	}
	
	public String mdsupList(){
		UserBO bo = new UserBO();
		page = new Page();
		List all;
		result = new ArrayList();
		try{
			all = bo.findAll(request);
		}
		catch(Exception e){
			e.printStackTrace();
			all = new ArrayList();
		}
		request.getSession().setAttribute("list", all);
		try{
			for(int i=0;i<WebConstants.PAGESIZE;i++){
				if(all.get(i)!=null){
					result.add(all.get(i));
				}
			}
		}catch(Exception e){
		}
		page.setCurrentPage(1);
		page.setPrePage(page.getCurrentPage()-1);
		page.setNextPage(page.getCurrentPage()+1);
		page.setListSize(all.size());
		page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
		return "mdsupList";
	}
	
	public String doorList(){
		PurviewBO bo =  new PurviewBO();
		FilterBO filterBO = new FilterBO();
		page = new Page();
		List all;
		areaList = bo.getOptionArea(request);
		districtList = bo.getOptionDistrict(areaId);
		buildingList = bo.getOptionBuilding(districtId);
		doorList = bo.getOptionDoor(buildingId);
		result = new ArrayList();
		try{
			all = filterBO.getRightVOList(bo.getDoorList(userId), request);
		}
		catch(Exception e){
			e.printStackTrace();
			all = new ArrayList();
		}
		request.getSession().setAttribute("list", all);
		try{
			for(int i=0;i<WebConstants.PAGESIZE;i++){
				if(all.get(i)!=null){
					result.add(all.get(i));
				}
			}
		}catch(Exception e){
		}
		page.setCurrentPage(1);
		page.setPrePage(page.getCurrentPage()-1);
		page.setNextPage(page.getCurrentPage()+1);
		page.setListSize(all.size());
		page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
		return "doorList";
	}

	public String activity(){
		PurviewBO bo =  new PurviewBO();
		bo.changeStateActivity(userId, doorId);
		return doorList();
	}
	
	public String inactivity(){
		PurviewBO bo =  new PurviewBO();
		bo.changeStateInactivity(userId, doorId);
		return doorList();
	}
	
	public String delete(){
		PurviewBO bo =  new PurviewBO();
		bo.delete(userId, doorId);
		return doorList();
	}
	
	public String add(){
		PurviewBO bo =  new PurviewBO();
		bo.add(userId, doorId);
		return doorList();
	}
	
	public String getOption(){
		return "doorList";
	}
	
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getCallId() {
		return callId;
	}

	public void setCallId(String callId) {
		this.callId = callId;
	}

	public String getWorkerNO() {
		return workerNO;
	}

	public void setWorkerNO(String workerNO) {
		this.workerNO = workerNO;
	}

	public Date getExpiryDate() {
		return expiryDate;
	}

	public void setExpiryDate(Date expiryDate) {
		this.expiryDate = expiryDate;
	}

	public String getUserDepartment() {
		return userDepartment;
	}

	public void setUserDepartment(String userDepartment) {
		this.userDepartment = userDepartment;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserPhone() {
		return userPhone;
	}

	public void setUserPhone(String userPhone) {
		this.userPhone = userPhone;
	}

	public String getUserEmail() {
		return userEmail;
	}

	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail;
	}

	public Integer getUserState() {
		return userState;
	}

	public void setUserState(Integer userState) {
		this.userState = userState;
	}

	public List getResult() {
		return result;
	}

	public void setResult(List result) {
		this.result = result;
	}

	public List getDeptList() {
		return deptList;
	}

	public void setDeptList(List deptList) {
		this.deptList = deptList;
	}

	public List getStateList() {
		return stateList;
	}

	public void setStateList(List stateList) {
		this.stateList = stateList;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getLogicMark0() {
		return logicMark0;
	}

	public void setLogicMark0(String logicMark0) {
		this.logicMark0 = logicMark0;
	}

	public String getLogicMark1() {
		return logicMark1;
	}

	public void setLogicMark1(String logicMark1) {
		this.logicMark1 = logicMark1;
	}

	public String getLogicMark2() {
		return logicMark2;
	}

	public void setLogicMark2(String logicMark2) {
		this.logicMark2 = logicMark2;
	}

	public String getLogicMark3() {
		return logicMark3;
	}

	public void setLogicMark3(String logicMark3) {
		this.logicMark3 = logicMark3;
	}

	public String getDoorId() {
		return doorId;
	}

	public void setDoorId(String doorId) {
		this.doorId = doorId;
	}

	public String getAreaId() {
		return areaId;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	public String getDistrictId() {
		return districtId;
	}

	public void setDistrictId(String districtId) {
		this.districtId = districtId;
	}

	public String getBuildingId() {
		return buildingId;
	}

	public void setBuildingId(String buildingId) {
		this.buildingId = buildingId;
	}

	public List getAreaList() {
		return areaList;
	}

	public void setAreaList(List areaList) {
		this.areaList = areaList;
	}

	public List getDistrictList() {
		return districtList;
	}

	public void setDistrictList(List districtList) {
		this.districtList = districtList;
	}

	public List getBuildingList() {
		return buildingList;
	}

	public void setBuildingList(List buildingList) {
		this.buildingList = buildingList;
	}

	public List getDoorList() {
		return doorList;
	}

	public void setDoorList(List doorList) {
		this.doorList = doorList;
	}
	
	
	
}
